import functools

from flask import current_app
from flask import g
from flask import session

from info.models import User


def set_index_class(num):
    if num == 1:
        return 'first'
    elif num == 2:
        return 'second'
    elif num == 3:
        return 'third'
    else:
        return ''


#user装饰器
def user_login_data(fun):
    @functools.wraps(fun)
    def wrapper(*args, **kwargs):
        user_id = session.get('user_id')  # 用户id
        user =None
        if user_id:
            try:
                user = User.query.get(user_id)  # 去数据库查出该用户信息
            except Exception as e:
                current_app.logger.error(e)
        g.user =user
        return fun(*args, **kwargs)
    return wrapper

